module t_ucordic8_decoder ();

reg [1:0] ADDR;
reg [7:0] DME;
wire [7:0] DEM;
reg nRD, nWE, nCS, nRESET, CLK;
wire nIDLE;
wire SELMUXEXTREGX, SELMUXEXTREGY, SELMUXEXTREGZ;
wire [1:0] SELMUXREGEXT;
wire ENX, ENY, ENZ, nCTRHOLD, ApproxMode;
wire [1:0] CoordMode;
wire [7:0] DataToCordicCore;
reg [7:0] DataFromCordicCore;
wire nResetToCordicCore;

task taskSetRegisterAny;
input [7:0] inputDataToRegister;
input [1:0] registerSelector;
begin
	/*Load Data Register*/
	ADDR = 2'b00;
	DME = inputDataToRegister;
	nCS = 1'b0;
	#5;
	nWE = 1'b0;
	#5;
	nWE = 1'b1;
	#5;
	nCS = 1'b1;
	#5;
	/*Execute SETX-CMD*/
	ADDR = 2'b01;
	DME = {6'b000001, registerSelector};
	nCS = 1'b0;
	#5;
	nWE = 1'b0;
	#5;
	nWE = 1'b1;
	#5;
	nCS = 1'b1;
	#5;
end
endtask

task taskGetRegisterAny;
input [1:0] registerSelector;
begin
	/*Load Command - GET?*/
	ADDR = 2'b01;
	DME = {6'b000011, registerSelector};
	nCS = 1'b0;
	#5;
	nWE = 1'b0;
	#5;
	nWE = 1'b1;
	#10;
	/*Export data to port*/
	ADDR = 2'b10;
	#5;
	nRD = 1'b0;
	#5;
	nRD = 1'b1;
	#5;
	nCS = 1'b1;
	#5;
end
endtask

task taskCalc;
input [2:0] inputCommand;
begin
	ADDR = 2'b01;
	DME = {5'b00010, inputCommand};
	nCS = 1'b0;
	#5;
	nWE = 1'b0;
	#5;
	nWE = 1'b1;
	#5;
	nCS = 1'b1;
	#5;
end
endtask

task taskReset;
begin
	ADDR = 2'b01;
	DME = 8'h00;
	nCS = 1'b0;
	#5;
	nWE = 1'b0;
	#5;
	nWE = 1'b1;
	#5;
	nCS = 1'b1;
	#5;
end
endtask

always
begin
	ADDR = 2'b00;
	DME = 8'h00;
	nRD = 1'b1; 
	nWE = 1'b1;
	nCS = 1'b1;
	nRESET = 1'b0;
	CLK = 1'b0;
	DataFromCordicCore = 8'h00;
	#5;
	nRESET = 1'b1;
	#5;
	/*Test code start*/
	taskSetRegisterAny(8'h27, 2'b00);
	taskGetRegisterAny(2'b00);
	/*END*/
	#64;
	$stop;
end

always
begin
	CLK = ~CLK;
	#1;
end

ucordic8decoder DUT (.ADDR(ADDR), .DME(DME), .DEM(DEM), .nRD(nRD), .nWE(nWE), .nCS(nCS), .nIDLE(nIDLE), .nRESET(nRESET), .CLK(CLK), .SELMUXEXTREGX(SELMUXEXTREGX), .SELMUXEXTREGY(SELMUXEXTREGY), .SELMUXEXTREGZ(SELMUXEXTREGZ), .SELMUXREGEXT(SELMUXREGEXT), .ENX(ENX), .ENY(ENY), .ENZ(ENZ), .nCTRHOLD(nCTRHOLD), .ApproxMode(ApproxMode), .CoordMode(CoordMode), .DataToCordicCore(DataToCordicCore), .DataFromCordicCore(DataFromCordicCore), .nResetToCordicCore(nResetToCordicCore));

endmodule
